package com.ttwm.controller;

import com.ttwm.pojo.Order;
import com.ttwm.pojo.OrderFood;
import com.ttwm.service.OrderFoodService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@CrossOrigin
public class OrderFoodController {
    @Autowired
    private OrderFoodService orderFoodService;

    @PostMapping(value = {"/ttwm/addOrderFood"})
    public Map<String ,Object> insetOrderFood(@RequestBody OrderFood orderFood){
        Map map = new HashMap<String ,Object>();
        int orderFoods = orderFoodService.insetOrderFood(orderFood);
        if (orderFoods>0){
            map.put("success",true);
            map.put("msg","成功");
        }else {
            map.put("success",false);
            map.put("msg","失败");
        }
        return map;
    }

    @PostMapping(value = {"/ttwm/deleteOrderFood"})
    public Map<String ,Object> deleteOrderFood(@RequestBody OrderFood orderFood){
        Map map = new HashMap<String ,Object>();
        int deleteOrderFood = orderFoodService.deleteOrderFood(orderFood);
        if (deleteOrderFood>0){
            map.put("success",true);
            map.put("msg","成功");
        }else {
            map.put("success",false);
            map.put("msg","失败");
        }
        return map;
    }

//    修改数量、和
    @PostMapping(value = {"/ttwm/updateSumTotal"})
    public Map<String ,Object> updateSumTotal(@RequestBody OrderFood orderFood){
        Map map = new HashMap<String ,Object>();
        int updateLocation = orderFoodService.updateSumTotal(orderFood);
        if (updateLocation>0){
            map.put("success",true);
            map.put("msg","成功");
        }else {
            map.put("success",false);
            map.put("msg","失败");
        }
        return map;
    }
}
